

//毫秒倒计时转化为时分秒(大于一小时显示小时,大于一分钟显示分钟,大于一秒显示秒)
String timeLength(int millSecend,{String? secendName,String? minuteName,String? hourName,String? dayName}) {
  if (millSecend < 0) {
    return "0${hourName ?? "小时"}0${minuteName ?? "分钟"}0${secendName ?? "秒"}";
  }
  int allSecend = millSecend~/1000;
  int sencend = allSecend%60;
  int minute = (allSecend~/60)%60;
  int hour = (allSecend~/(60*60))%24;
  int day = allSecend~/(24*60*60);

  String timeStr = "";
  if (day > 0) {
    timeStr = timeStr+"$day${dayName ?? "天"}";
  }
  timeStr = timeStr+"$hour${hourName ?? "小时"}";
  timeStr = timeStr+"$minute${minuteName ?? "分钟"}";
  timeStr = timeStr+"$sencend${secendName ?? "秒"}";
  return timeStr;
}

//秒倒计时转化为时分秒(大于一小时显示小时,大于一分钟显示分钟,大于一秒显示秒)
String timeLengthWithSecond(int allSecend,{String? secendName,String? minuteName,String? hourName,String? dayName}) {
  if (allSecend < 0) {
    return "0${hourName ?? "小时"}0${minuteName ?? "分钟"}0${secendName ?? "秒"}";
  }
  int sencend = allSecend%60;
  int minute = (allSecend~/60)%60;
  int hour = (allSecend~/(60*60))%24;
  int day = allSecend~/(24*60*60);

  String timeStr = "";
  if (day > 0) {
    timeStr = timeStr+"$day${dayName ?? "天"}";
  }
  timeStr = timeStr+"$hour${hourName ?? "小时"}";
  timeStr = timeStr+"$minute${minuteName ?? "分钟"}";
  timeStr = timeStr+"$sencend${secendName ?? "秒"}";
  return timeStr;
}

//目标时间与当前时间差转化为时分秒(大于一小时显示小时,大于一分钟显示分钟,大于一秒显示秒)
String timeLengthFromNow(int millSecend,{String? secendName,String? minuteName,String? hourName,String? dayName}) {
  int timeDiff = getTimeDiff(millSecend);
  return timeLength(timeDiff,secendName: secendName,minuteName: minuteName,hourName: hourName,dayName: dayName,);
}

//获取与当前时间差
int getTimeDiff(int millSecend) {
  return millSecend - DateTime.now().millisecondsSinceEpoch;
}
